Skip to content

Refactor providers around a functional core - #263

Merged
Jawnnypoo merged 1 commit into
mainfrom
refactor/functional-provider-core
Jul 27, 2026
Merged

Refactor providers around a functional core#263
Jawnnypoo merged 1 commit into
mainfrom
refactor/functional-provider-core

Conversation

@VeldtJumper

Copy link
Copy Markdown
Contributor

Summary

  • replace the mutable class-based provider hierarchy with stateless defineProvider and defineEventProvider definitions
  • migrate all 29 providers to the uniform functional API and make provider definitions the single source of metadata
  • centralize request normalization, event dispatch, ignored-event handling, provider defaults, Discord finalization, mention suppression, and aggregate payload limits
  • add policy-bound provider HTTP for bounded JSON enrichment and migrate Trello away from unrestricted fetch
  • add shared webhook scalar, ID, integer, timestamp, and trusted-URL helpers
  • add a provider scaffold command that generates and registers a working provider, canonical fixture, test, and README entry
  • add repository-wide provider contract, definition, HTTP-policy, and scaffold tests
  • remove BaseProvider, DirectParseProvider, TypeParseProvider, reflective dispatch, and compatibility branches
  • split core internals under src/provider/core/ while keeping src/provider/Provider.ts as the small public authoring facade
  • rewrite provider-authoring documentation around the functional API

Provider authoring

A new provider can now be generated with:

npm run provider:new -- newprovider NewProvider "New Provider" https://docs.example.com/webhooks

The generated provider primarily maps normalized webhook JSON into a Discord draft:

export const NewProvider = defineProvider({
    path: 'newprovider',
    name: 'New Provider',
    example: { body: 'newprovider/newprovider.json' },
    map({ body }, output) {
        const event = firstScalar(body.event, body.type) ?? 'New Provider notification'
        output.addEmbed({ title: event })
    },
})

Safety and behavior

  • finalized payloads always suppress mentions with allowed_mentions: { parse: [] }
  • Discord component limits and the message-wide 6,000-character embed budget are enforced centrally
  • invalid URLs, timestamps, colors, fields, and optional embed components are omitted during finalization
  • empty drafts fail fast; unsupported events must call output.ignore()
  • event dispatch accepts only bounded exact string keys and never reflects into provider methods
  • provider HTTP requires an explicit HTTPS hostname allowlist, rejects credentials and non-default ports, rejects redirects, has bounded time and response size, and cancels oversized streams while reading

Verification

  • npm test — 207 passed, 0 failed
  • npm run lint — 95 files clean
  • npx tsc --noEmit — passed
  • npm run build — passed
  • cd web && npm test — passed
  • cd web && npm run build — passed
  • generated-provider integration test in a temporary full checkout — generated provider compiled, passed focused and contract tests, and passed lint
  • git diff --check — passed

@Jawnnypoo
Jawnnypoo merged commit 98e96a8 into main Jul 27, 2026
1 check passed
@Jawnnypoo
Jawnnypoo deleted the refactor/functional-provider-core branch July 27, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants